package com.cn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.api.ApiCode;
import com.cn.api.ApiResult;
import com.cn.mapper.ShopSpecMapper;
import com.cn.pojo.shop.ShopSpec;
import com.cn.service.ShopSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 28631
* @description 针对表【shop_spec(规格)】的数据库操作Service实现
* @createDate 2024-02-29 15:12:20
*/
@Service
public class ShopSpecServiceImpl extends ServiceImpl<ShopSpecMapper, ShopSpec>
    implements ShopSpecService {

    @Autowired
    private ShopSpecMapper shopSpecMapper;

    /**
     * 查询规格数据
     * @return
     */
    @Override
    public ApiResult querySpec() {
        List<ShopSpec> shopSpecs = shopSpecMapper.selectList(null);
        return ApiResult.success(shopSpecs);
    }

    /**
     * 修改规格数据
     * @param shopSpec 规格
     * @param id
     * @return
     */
    @Override
    public ApiResult updateSpec(ShopSpec shopSpec, Integer id) {
        shopSpec.setCommodityId(id);
        shopSpecMapper.insert(shopSpec);
        return ApiResult.success(ApiCode.SUCCESS);
    }

    /**
     * 规格
     * @param shopSpec 规格
     * @param id 商品
     * @return
     */
    @Override
    public ApiResult addSpec(ShopSpec shopSpec, Integer id) {
        shopSpec.setCommodityId(id);
        shopSpecMapper.updateById(shopSpec);
        return ApiResult.success(ApiCode.SUCCESS);
    }

    /**
     * 删除规格信息
     * @param id
     * @return
     */
    @Override
    public ApiResult deleteSpec(Integer id) {
        shopSpecMapper.deleteById(id);
        return ApiResult.success(ApiCode.SUCCESS);
    }
}




